import { reqHomeData, reqCategoryData, reqNavList, reqgoodsList } from "../../api/home/index";

const state = {
  homeList: {},
  categoryList: {},
  list: [],
  cateList: [],


  goodsList: [],
};
const mutations = {
  GETHOMEDATA(state, homeList) {
    state.homeList = homeList;
    // console.log('123',homeList)
  },
  GETCATEGORYDATALIST(state, categoryList) {
    state.categoryList = categoryList;
  },
  // 另一个接口
  GETNavLIST(state, list) {
    state.list = list;
  },
  GETCATELIST(state, data) {
    state.cateList = data;
  },
  GETGOODSLIST(state,goodsList){
    state.goodsList = goodsList
  }
};
const actions = {
  // home页
  async getHomeData({ state, commit, dispatch }) {
    let result = await reqHomeData();
    // console.log(result);
    commit("GETHOMEDATA", result.data);
  },

  // 分类导航
  //  async getCategoryDataList({ state, commit, dispatch }) {
  //   let result = await reqCategoryData();
  //   // console.log(result);
  //   commit("GETCATEGORYDATALIST", result.data);
  // },
  // 根据id获取分类导航数据
  async getNavList({ state, commit, dispatch }) {
    let result = await reqNavList();
    // console.log(result);
    commit("GETNavLIST", result.data || []);
    commit("GETCATELIST", result.global);
  },
  // 分类导航列表
  async getGoodsList({ state, commit, dispatch }, categoryId) {
    let result = await reqgoodsList(categoryId);
    console.log(result.data);
    commit("GETGOODSLIST", result.data);
  },
};

const getters = {
  // 三个小图标数据
  policyDescList() {
    return (state.homeList.data || {}).policyDescList || [];
  },
  // 导航栏数据
  categoryList() {
    return ((state.homeList.data || {}).categoryHotSellModule || {}).categoryList || [];
  },
  // 轮播图数据
  focusList() {
    return (state.homeList.data || {}).focusList || [];
  },
  // 十个小图数据
  kingKongModuleList() {
    return ((state.homeList.data || {}).kingKongModule || {}).kingKongList || [];
  },
  // 新人专享礼数据

  // 福利社 新人拼团
  indexActivityModuleList() {
    return (state.homeList.data || {}).indexActivityModule || [];
  },
  // 生活家居 酒水美食
  twoList() {
    return (((state.homeList.data || {}).categoryHotSellModule || {}).categoryList || []).slice(0, 2);
  },
  sixList() {
    return (((state.homeList.data || {}).categoryHotSellModule || {}).categoryList || []).slice(2, 8);
  },
  // 潮流馆
  //  shoppingList(){
  //   return (state.homeList.data ||{}).sceneLightShoppingGuideModule || []
  // },

  shopping1List() {
    return ((state.homeList.data || {}).sceneLightShoppingGuideModule || []).splice(0, 1);
  },
  shopping2List() {
    return ((state.homeList.data || {}).sceneLightShoppingGuideModule || []).splice(0, 2);
  },
  // 分类数据
  // 轮播图
  swiperList() {
    return ((state.categoryList || {}).currentCategory || {}).bannerList || [];
  },

  // 另一个接口
  // 分类导航数据
  cateList() {
    return (state.cateList || []).cateList;
  },

  // Life组件的商品数据
  // 轮播图
  swiperList(){
    return ((state.goodsList ||[]).currentCategory|| {}).bannerList ||[]
  },
  // 每个商品的Card卡片的数据
  categoryItemList(){
    return (state.goodsList ||[]).categoryItemList ||[]
  },
  // 每个商品的数据
  itemList(){
    return ((state.goodsList ||[]).categoryItemList ||[]).itemList ||[]
  }

};

export default {
  namespaced: "home",
  state,
  actions,
  mutations,
  getters,
};
